/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;
import model.Artist;
import java.util.Date;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import model.MusicGenre;
import model.MusicGroup;

/**
 *
 * @author Eleftherios
 */

public class ArtistObj {
    
  private Integer artistid;   
  private String firstname;            
  private String lastname;     
  private String artisticname;
  private String sex;
  private Date birthday;
  private String birthplace;
  private MusicGenre musicgerne;
  
   public ArtistObj(Integer artist_id, String firstname, 
                   String lastname, String artisticname, 
                   String sex, Date birthday, String birthplace, 
                   MusicGenre musicgerne) {
        this.artistid = artist_id;
        this.firstname = firstname;
        this.lastname = lastname;
        this.artisticname = artisticname;
        this.sex = sex;
        this.birthday = birthday;
        this.birthplace = birthplace;
        this.musicgerne = musicgerne;
   }
   
   public ArtistObj(){
       
   }
   
    public Integer getArtist_id() {
        return artistid;
    }

    public void setArtistid(Integer artistid) {
        this.artistid = artistid;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFist_name(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setlast_name(String lastname) {
        this.lastname  = lastname;
    }

    public String getArtisticname() {
        return artisticname;
    }

    public void setArtisticname(String artisticname) {
        this.artisticname  = artisticname;
    }
    
    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex  = sex;
    }
    
     public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday  = birthday;
    }

    public String getBirthplace() {
        return birthplace;
    }

    public void setBirthplace(String birthplace) {
        this.birthplace  = birthplace;
    }

     public MusicGenre getMusicgerne() {
        return musicgerne;
    }

    public void setMusic_gerne(MusicGenre musicgerne) {
        this.musicgerne = musicgerne;
    }
       
    public void bindList(javax.swing.JTable JT, int MusicGroupId, int whatToDo)   { 
              // whatToDo = 0 όλοι οι artists, 
              // whatToDo = 1 τους artists του group 
              // whatToDo = 2 εκτος απο τους artist του group
            
       DefaultTableModel model = (DefaultTableModel) JT.getModel(); // ανάκληση του model απο το αντικείμενο του πίνακα                     
       for (int i=model.getColumnCount()-1; i>-1; i--) {  // καθάρισε τις Στήλες 
          TableColumn col = JT.getColumnModel().getColumn(i); 
           JT.removeColumn(col);
           model.setColumnCount(model.getColumnCount()-1);
           JT.revalidate(); 
       }
       // Ορίζω νέες στήλες 
       model.addColumn("Κωδικός");
       model.addColumn("Όνομα");
       model.addColumn("Επίθετο");
       model.addColumn("καλλιτεχνικό Όνομα");
       model.addColumn("Genre");
       
       for (int c = 0; c < JT.getColumnCount(); c++)  // ο πίνακας γίνεται read only
       {
               Class<?> col_class = JT.getColumnClass(c);
               JT.setDefaultEditor(col_class, null);        
       }      
       for (int i=model.getRowCount()-1; i>-1; i--){ model.removeRow(i);} // καθάρισε τις γραμμές   
       
       // μεταφορά των δεδομένων στον πίνακα
       Artist MyClass = new Artist();
       List<Artist> list;
       if(whatToDo==0) {         
           list = MyClass.read(Boolean.TRUE, "");
       }
       else
       {
           MusicGroup MCClass = new MusicGroup();
           MCClass.setMusicGroupId(MusicGroupId);
           String tmp = JT.getName();
           if(whatToDo==1) {list = MCClass.getArtistList(false);}
           else
           {list = MCClass.getArtistList(true);}
           
       }
       
       for (int i=0; i < list.size(); i++)
         {
             model.addRow(new Object[]{list.get(i).getArtistId().toString(), 
                                       list.get(i).getFirstName(), 
                                       list.get(i).getLastName(), 
                                       list.get(i).getArtisticName(), 
                                       list.get(i).getMusicGenre().getName()});
         }
    }
 
    public void ReadArtist() {
        Artist MyClass = new Artist();
        MyClass.setArtistId(artistid);
        MyClass.read(Boolean.FALSE, "");
        
        artistid=MyClass.getArtistId();   
        firstname=MyClass.getFirstName();            
        lastname=MyClass.getLastName();
        artisticname=MyClass.getArtisticName();
        sex=MyClass.getSex();
        birthday=MyClass.getBirthday();
        birthplace=MyClass.getBirthplace();
        musicgerne=MyClass.getMusicGenre();
    }
    
    
    public long update(){
        Artist MyClass = new Artist();
        MyClass.setArtistId(artistid);
        MyClass.setFirstName(firstname);
        MyClass.setLastName(lastname);
        MyClass.setArtisticName(artisticname);
        MyClass.setSex(sex);
        MyClass.setBirthday(birthday);
        MyClass.setBirthplace(birthplace);
        MyClass.setMusicGenre(musicgerne);        
        return MyClass.update();
    }
    
        
    public long AddNew(){
        Artist MyClass = new Artist();
        MyClass.setArtistId(artistid);
        MyClass.setFirstName(firstname);
        MyClass.setLastName(lastname);
        MyClass.setArtisticName(artisticname);
        MyClass.setSex(sex);
        MyClass.setBirthday(birthday);
        MyClass.setBirthplace(birthplace);
        MyClass.setMusicGenre(musicgerne);        
        return MyClass.insert();
    }
    
    public long AddNew_Has_Group(int Music_Group_Id, int Artist_Id){
        Artist MyClass = new Artist();
        return MyClass.InsertMusicGroup(Music_Group_Id, Artist_Id);
    }
    
    public long delete(){
        Artist MyClass = new Artist();
        MyClass.setArtistId(artistid);
        return MyClass.delete();
    }
    
    public long delete_Has_Group(int Music_Group_Id, int Artist_Id){
        Artist MyClass = new Artist();
        return MyClass.deleteMusicGroup(Music_Group_Id, Artist_Id);
    }
    
    @Override
    public String toString() {
        return " Artist control class";
    }
}
